﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Honestysoft.Financing.Model;
using System.IO;

namespace Honestysoft.Financing.WebUI.Module.Audit
{
    public partial class ATPrint : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //window.open('Bu_AuditTable_Print.aspx?ID=<%=Request["ID"]+"" %>&FunctionID=<%=Request["FunctionID"]+"" %>&Status=<%= _BuStatus %>&FilePath=' + escape("<%=_SwfFilePath %>"));

            if (!IsPostBack)
            {
                string swfFilePath = AuditUtils.ExportToExcel(Request.QueryString["ID"]);
                System.Threading.Thread.Sleep(1000);
                bool bExists = false;
                bExists = File.Exists(Server.MapPath(swfFilePath));
                while (!bExists)
                {
                    System.Threading.Thread.Sleep(2000);
                    bExists = File.Exists(Server.MapPath(swfFilePath));
                }
                Response.Redirect(swfFilePath);

                //string swfFilePath = "";
                //if (Request.QueryString["Wait"] == "1")
                //{
                //    swfFilePath = Request.QueryString["FilePath"];
                //}
                //else
                //{
                //    swfFilePath = AuditUtils.ExportToExcel(Request.QueryString["ID"]);
                //}
                ////if (Request.QueryString["Status"] != ((int)EnumItem.AuditTableStatus.Output).ToString()
                ////    && Request.QueryString["Status"] != ((int)EnumItem.AuditTableStatus.Lock).ToString())
                ////{
                //    //swfFilePath = AuditUtils.ExportToExcel(Request.QueryString["ID"]);
                ////}
                ////else
                ////{
                ////    swfFilePath = Request.QueryString["FilePath"] + ".swf";
                ////}
                //Page.ClientScript.RegisterStartupScript(this.GetType(), "hide", "window.parent.unlocking()", true);
                //if (File.Exists(swfFilePath))
                //{
                //    Response.Redirect(swfFilePath);
                //}
                //else
                //{
                //    System.Threading.Thread.Sleep(2000);
                //    Response.Redirect("ATPrint.aspx?Wait=1&FilePath="+Server.UrlEncode(swfFilePath));
                //}
            }
        }
    }
}